#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
const int maxn = 3e3+10;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double ohuo = 1e-6;
int d[4][2]={1,0,0,1,-1,0,0,-1};
long double fac[maxn];
int main() {
    ios::sync_with_stdio(0);
    #ifdef Uncle_drew
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #else
    #endif
    fac[0]=0.0;
    for(int i=1;i<=2510;i++){
        fac[i]=fac[i-1]+log(i);
        // cout<<fac[i]<<endl;
    }
    int t,a,b,c,mid;
    cin>>t;
    for(int ca=1;ca<=t;ca++){
        cin>>a>>b>>c;
        double x=0,y=0,z=0;
        while(a--){
            cin>>mid;
            x+=fac[mid];
        }
        while(b--){
            cin>>mid;
            y+=fac[mid];
        }
        while(c--){
            cin>>mid;
            z+=fac[mid];
        }
        cout<<"Case #"<<ca<<": ";
        if(x-y>ohuo&&x-z>ohuo){
            cout<<"A";
        }
        else if(y-x>ohuo&&y-z>ohuo){
            cout<<"B";
        }
        else if(z-y>ohuo&&z-x>ohuo){
            cout<<"C";
        }
        else{
            cout<<"TIE";
        }
        cout<<endl;
    }
    return 0;
}
